//
//  ZYCNavigationController.m
//  ZDSC
//
//  Created by ZDTX on 2021/5/14.
//

#import "ZYCNavigationController.h"
#import "UIView+Gt.h"
#import "UIButton+EnlargeEdge.h"
@interface ZYCNavigationController ()<UIGestureRecognizerDelegate>

@end

@implementation ZYCNavigationController

+ (void)load {
    UINavigationBar *bar = [UINavigationBar appearance];
    bar.translucent = NO;
    //设置导航栏背景色
    if (@available(iOS 15.0, *)) {
            UINavigationBarAppearance *barApp = [UINavigationBarAppearance new];
        barApp.backgroundColor = HEX_RGB(kBgGreenColor);
            bar.scrollEdgeAppearance = barApp;
            bar.standardAppearance = barApp;
        [barApp setTitleTextAttributes:@{NSFontAttributeName:kSystemFont(18.0f),NSForegroundColorAttributeName:HEX_RGB(kTitleWhiteColor)}];
        }
    bar.barTintColor = HEX_RGB(kBgGreenColor);

    // 设置导航栏字体颜色
    [bar setTitleTextAttributes:@{NSFontAttributeName:kSystemFont(18.0f),NSForegroundColorAttributeName:HEX_RGB(kTitleWhiteColor)}];
//
//    UIBarButtonItem *item = [UIBarButtonItem appearance];
//    NSMutableDictionary *itemAttD = [NSMutableDictionary dictionary];
//    itemAttD[NSFontAttributeName] = kSystemFont(18.0f);
//    itemAttD[NSForegroundColorAttributeName] = [UIColor whiteColor];
//    [item setTitleTextAttributes:itemAttD forState:UIControlStateNormal];
//
//    NSMutableDictionary *itemDisAttD = [NSMutableDictionary dictionary];
//    itemDisAttD[NSFontAttributeName] = kSystemFont(18.0f);
//    itemDisAttD[NSForegroundColorAttributeName] = HEX_RGB(kTitleWhiteColor);
//    [item setTitleTextAttributes:itemDisAttD forState:UIControlStateSelected];
}

- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.childViewControllers.count > 0) {
//        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//        [button setImage:[UIImage imageNamed:@"Path"] forState:UIControlStateNormal];
//        button.frame = CGRectMake(0, 0, 16, 26);
//        button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
//        button.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
//        button.imageEdgeInsets = UIEdgeInsetsMake(5, 8, 5, 8);
//        [button setEnlargeEdgeWithTop:40 right:40 bottom:40 left:40];
//        [button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
//        viewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
        viewController.hidesBottomBarWhenPushed = YES;
    }
    [super pushViewController:viewController animated:animated];
}

- (void)back {
    [self popViewControllerAnimated:YES];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    // 开启系统自带的侧滑
    self.interactivePopGestureRecognizer.delegate = self;
    

    
//    //设置系统自带的返回按钮图片
//    [[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:@"Chevron"]];
//    [[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:@"Chevron"]];
//    //设置返回按钮颜色
//    [[UIBarButtonItem appearance] setTintColor:[UIColor colorWithHexString:@"FFFFFF" alpha:1.0]];
//    self.navigationBar.tintColor = [UIColor colorWithHexString:@"FFFFFF" alpha:1.0];
}

#pragma mark - UIGestureRecognizerDelegate

- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
    // 注意: 只有非根控制器才有滑动返回按钮 根控制没有
    if (self.childViewControllers.count == 1) {
        return NO;
    }else{
        return YES;
    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
